/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package game;

import botchat.*;
import java.io.Serializable;
import java.util.ArrayList;
import other.Costants;

/**
 *
 * @author alessandro
 */
public class BOT implements Serializable{
    private String name;
    private String state;
    
    public BOT(String name) {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public static Card play(ArrayList<Card> cards, String firstseed, boolean hearts) {
        Card card = null;

        Card twoFlowers = new Card(Costants.SEED_F, 2);
        twoFlowers.setState(Costants.HOLD_BY_USER);

        boolean flag = false;

        int isTwoOnCards = cards.indexOf(twoFlowers);
        if(isTwoOnCards != -1) {
            card = twoFlowers;
            flag = true;
        } else {
            if(firstseed != null) {
                for(int i=0; i<cards.size(); i++) {
                    if(cards.get(i).getSeed().equals(firstseed)) {
                       card = (Card)cards.get(i);
                       flag = true;
                       break;
                    }
                }
            } else {
                if(hearts) {
                    //si può implementare un'intelligenza più intelligente
                    card = (Card)cards.get((int)(cards.size()*Math.random()));
                    flag = true;
                } else {
                    int contatore = 0;
                    do {
                        card = (Card)cards.get(contatore);
                        contatore++;
                        if(!(card.getSeed().equals(Costants.SEED_C))) {
                            flag = true;
                            break;
                        }
                    } while(card.getSeed().equals(Costants.SEED_C) && contatore < cards.size());
                }

            }
            //controllo se ha giocato una carta
            if(!flag) {
                //si può implementare un'intelligenza più intelligente
                card = (Card)cards.get((int)(cards.size()*Math.random()));
            }
        }

        return card;
    }

    public static String talk(String message) {
        String messageBot = "";
        try {
            ChatterBotFactory factory = new ChatterBotFactory();

            ChatterBot bot1 = factory.create(ChatterBotType.CLEVERBOT);
            ChatterBotSession bot1session = bot1.createSession();

            messageBot = bot1session.think(message);

        } catch (Exception e) {
            System.out.println("Il bot non risponde");
        }
        return messageBot;
    }


}
